<template>
  <div class="follow">
    <ProfileTopNav title="我的关注" path="/user" />
    <div class="list">
      <div class="item" v-for="item in followList" :key="item.id">
        <img
          v-if="item.head_img"
          :src="
            // 过滤器 凡是没有基础路径的图片为他添加
            item.head_img | flxImgUrl
          "
          alt=""
          class="avatar"
        />
        <img v-else src="../../../image/1.jpg" alt="" class="avatar" />
        <div class="info">
          <div class="name">{{ item.nickname || item.username }}</div>
          <div class="date">1998-05-28</div>
        </div>
        <div class="btn" @click="offFollow(item.id)">取消关注</div>
      </div>
    </div>
    <Return father=".follow" paths="/user" />
  </div>
</template>

<script>
import ProfileTopNav from "@/components/TopNav";
import Return from "@/components/Return";
export default {
  data() {
    return {
      followList: [],
    };
  },
  components: {
    ProfileTopNav,
    Return,
  },
  created() {
    this.loadPage();
  },
  methods: {
    loadPage() {
      this.$axios({
        url: "/user_follows",
      }).then((res) => {
        console.log(res.data);
        const { data } = res.data;
        this.followList = data;
      });
    },
    // 取消关注
    offFollow(id) {
      this.$axios({
        url: "/user_unfollow/" + id,
      }).then((res) => {
        // 重新获取页面关注
        this.loadPage();
      });
    },
  },
};
</script>
<style lang="less" scoped>
.item {
  display: flex;
  align-items: center;
  padding: 20 / 360 * 100vw;
  border-bottom: 1px solid #ddd;
  .avatar {
    width: 40 / 360 * 100vw;
    height: 40 / 360 * 100vw;
    object-fit: cover;
    border-radius: 50%;
  }
  .info {
    flex: 1;
    padding-left: 10 / 360 * 100vw;
    .name {
      font-size: 16 / 360 * 100vw;
      color: #333;
    }
    .date {
      font-size: 14 / 360 * 100vw;
      color: #888;
    }
  }
  .btn {
    height: 38 / 360 * 100vw;
    line-height: 38 / 360 * 100vw;
    font-size: 16 / 360 * 100vw;
    padding: 0 20 / 360 * 100vw;
    border-radius: 19 / 360 * 100vw;
    background-color: #e5e5e5;
    color: #888;
  }
}
</style>